<?php

namespace App\Admin\Controllers;

use App\Models\TcmMedicineddietDetail;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class TcmMedicineddietDetailController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new TcmMedicineddietDetail(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('name');
            //$grid->column('shareImg');
            $grid->column('picture')->image('',50,50);
            //$grid->column('classification');
            //$grid->column('foods');
            //$grid->column('manufacture');
            //$grid->column('function');
            $grid->column('source');
            //$grid->column('created_at');
            //$grid->column('updated_at')->sortable();
        
            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
        
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new TcmMedicineddietDetail(), function (Show $show) {
            $show->field('id');
            $show->field('name');
            $show->field('shareImg')->image('',50,50);
            $show->field('picture')->image('',50,50);
            $show->field('classification');
   
			$show->field('foods')->unescape()->as(function ($html) {
				return $html;
			});
			$show->field('manufacture')->unescape()->as(function ($html) {
				return $html;
			});
			$show->field('function')->unescape()->as(function ($html) {
				return $html;
			});

            $show->field('source');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new TcmMedicineddietDetail(), function (Form $form) {
			$form->tab('基本信息', function (Form $form) {
				$form->display('id');
				$form->text('name');
				$form->image('shareImg')->uniqueName()->autoUpload()->saveFullUrl();
				$form->image('picture')->uniqueName()->autoUpload()->saveFullUrl();
				$form->text('classification');
				$form->text('source');
			});
			
			$form->tab('功效', function (Form $form) {
			   $form->editor('function');
			});
			
			$form->tab('食材', function (Form $form) {
			   $form->editor('foods');
			});
			$form->tab('制法', function (Form $form) {
			   $form->editor('manufacture');
			});
            
        
            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
